from flask_restx import Namespace, fields

from app.scheme import RESULT_SCHEME


ns = Namespace("user", description="用户管理")

user = {
    "id": fields.Integer(),
    "username": fields.String(description="用户名"),
    "nickname": fields.String(description="昵称"),
}

users = ns.model(
    "users",
    {
        **RESULT_SCHEME,
        "data": fields.Nested(
            {
                "total": fields.Integer(),
                "list": fields.List(
                    fields.Nested(user),
                ),
            }
        ),
    },
)

user_in = ns.model(
    "user_in",
    {
        "username": fields.String(required=True, description="用户名"),
        "nickname": fields.String(required=True, description="昵称"),
        "password": fields.String(required=True, description="昵称"),
    },
)

user_in_without_passwd = ns.model(
    "user_in_without_passwd",
    {
        "username": fields.String(required=True, description="用户名"),
        "nickname": fields.String(required=True, description="昵称"),
    },
)

user_out = ns.model(
    "user_out",
    {
        **RESULT_SCHEME,
        "data": fields.Nested(user),
    },
)

user_in_login = ns.model(
    "user_in_login",
    {
        "username": fields.String(required=True, description="用户名"),
        "password": fields.String(required=True, description="昵称"),
    },
)

user_out_login = ns.model(
    "user_out_login",
    {
        **RESULT_SCHEME,
        "data": fields.Nested({
            "token": fields.String(required=True, description="Token"),
            "refresh_token": fields.String(required=True, description="Refresh Token"),
        }),
    },
)
